<template>
<section v-loading="list_loading">
  <div class="searchbox">
      <el-form inline :model="query"  class="demo-form-inline fl" @submit.native.prevent>
        <el-form-item>
          <el-input size="medium" v-model="query.k" placeholder="教练姓名或手机号"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="small" icon="el-icon-search" @click="doSearch">搜&nbsp;&nbsp;索</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div @contextmenu="$parent.addMenu([{name:'刷新请假记录',method:'getData',icon:'icon-shuaxin'}])">
      <el-table :data="listData" tooltip-effect="dark" highlight-current-row style="width: 100%;text-align:center">
          <el-table-column prop="real_name" label="姓名"></el-table-column>
          <el-table-column label="性别">
            <template slot-scope="scope">
                <span v-if="scope.row.sex==0">未知</span>
                <i v-else-if="scope.row.sex==1" class="iconfont icon-nanxing" style="color:#31C8A4"></i>
                <i v-else="scope.row.sex==2" class="iconfont icon-nvxing" style="color:#ea727f"></i>
            </template>
          </el-table-column>
          <el-table-column prop="mobile" label="手机号"></el-table-column>
          <el-table-column label="请假开始时间">
            <template slot-scope="scope">{{ scope.row.begin_time|date('Y-m-d H:i') }}</template>
          </el-table-column>
          <el-table-column label="请假结束时间">
            <template slot-scope="scope">{{ scope.row.end_time|date('Y-m-d H:i') }}</template>
          </el-table-column>
          <el-table-column prop="duration" label="时长"></el-table-column>
          <el-table-column label="状态">
            <template slot-scope="scope">
                <el-button v-if="scope.row.status==0" @click.stop="audit_confirm(scope.row)" size="mini" round>待审批</el-button>
                <font color="#31C8A4" v-else-if="scope.row.status==1">已通过</font>
                <font color="#ccc" v-else-if="scope.row.status==2">已拒绝</font>
            </template>
          </el-table-column>
      </el-table>
      <div class="breakpage" v-if="page.total>0">
        <el-pagination background layout="total,sizes,prev, pager, next"
            :total="parseInt(page.total)"
            :page-size="parseInt(page.pagesize)"
            :current-page="parseInt(page.curpage)"
            @size-change="sizeChange"
            @current-change="pageChange">
        </el-pagination>
      </div>
    </div>

    <el-dialog title="审批" :visible.sync="audit_dialog.show" width="20%" custom-class="audit_dialog">
        <i class="el-icon-info" style="color:orange;margin-right:5px"></i><span>您是否批准{{audit_dialog.data.real_name}}的请假申请？</span>
        <span slot="footer" class="dialog-footer">
          <el-button size="small" @click="audit(2)">拒 绝</el-button>
          <el-button size="small" type="primary" @click="audit(1)">同 意</el-button>
        </span>
    </el-dialog>
</section>
</template>

<script>
import * as api from '../api/index'
import {date} from '../lib/function'
  export default {
    name:'leave',//页面名称
    data() {
      return {
    		m:'leave',
        dia:false,
        audit_dialog:{
          show:false,
          data:{},
        },
        query:{},//列表搜索条件
      }
    },
    computed:{
       listData(){
           return this.$store.state[this.m].data;
       },
       page(){
           return this.$store.state[this.m].page;
       },
       list_loading(){
           return this.$store.state[this.m].list_loading;
       }
     },
    filters:{date},
    methods: {
      audit_confirm(row){
        this.audit_dialog.data=row;
        this.audit_dialog.show=true;
      },
      audit(status){
        api.leave.audit({id:this.audit_dialog.data.id,status},res=>{
            if(res.status==1)  this.getData();
            else  this.$notify({type: 'error',title:'操作失败',message:res.info});
            this.audit_dialog.show=false;
         });
      },
      doSearch(){//查询数据
        this.query.p=1;
        this.getData();
      },
      sizeChange(size){
         //console.log(s);
         this.query.pagesize=size;
         this.getData();
      },
      pageChange(p){
        this.query.p=p;
        this.getData();
      },
     getData(){//获取教练列表数据
       this.$store.dispatch(
           this.m+'/getListData',
         JSON.parse(JSON.stringify(this.query))
       );
     }
    },
    created(){
      if(this.$parent.school.current.id==undefined||this.$store.state[this.m].school_id!=this.$parent.school.current.id) {
        this.query={};
        this.getData();
        this.$store.commit(this.m+'/update',{type:'school_id',data:this.$parent.school.current.id});
      }else{
        this.query=JSON.parse(JSON.stringify(this.$store.state[this.m].query));
      }
    }
  }
</script>
